#import <Foundation/Foundation.h>
#import <objc/runtime.h>

#import "FWDetailListEntry.h"
#import "FWDetailListSection.h"


@implementation FWDetailListSection

@synthesize title, entries, draggable;


// ******************************************************************************************
#pragma mark -
#pragma mark Helper methods to construct standard section types

+ (FWDetailListSection*)sectionForElements:(NSArray *)elements
{
    FWDetailListSection* section = [[[FWDetailListSection alloc] init] autorelease];

    section->entries = [[NSMutableArray arrayWithArray:elements] retain];
    
    return section;
}

+ (FWDetailListSection*)sectionForElements:(NSArray*)elements withTitle:(NSString*)title
{
    FWDetailListSection* section = [[[FWDetailListSection alloc] init] autorelease];

    section->title = [title copy];
    section->entries = [[NSMutableArray arrayWithArray:elements] retain];
    
    return section;
}

- (void)dealloc
{
    [title release];
    [entries release];
    
    [super dealloc];
}

- (FWDetailListSection*)withDraggableType
{
    self.draggable = YES;
    return self;
}

- (NSString*)description
{
    NSMutableString* reply = [NSMutableString stringWithFormat:@"<%@: %p;"
                              " title = %@;"
                              " draggable = %i;"
                              " entries = (",
                              [self class],
                              self,
                              self.title,
                              self.draggable];

    for (FWDetailListEntry* entry in entries) {
        [reply appendString:@"\r    "];
        [reply appendString:entry.description];
    }
    
    [reply appendString:@")>"];
    
    return reply;
}

@end
